home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 January: Mac OS SDK / Dev.CD Jan 00 SDK1.toast / Development Kits / Mac OS / Navigation Services SDK / Examples / Sampler / Sampler ƒ / document.c < prev    next >
Encoding:
Text File  |  1999-06-16  |  18.3 KB  |  715 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        document.c
  3.  
  4.     Copyright:    © 1997-1998 by Apple Computer, Inc., all rights reserved.
  5.  
  6. */
  7.  
  8. //    
  9. //    You may incorporate this sample code into your applications
  10. //    without restriction. This sample code has been provided "AS
  11. //    IS" and the responsibility for its operation is 100% yours.
  12. //    You are not permitted to redistribute the source as "Apple
  13. //    sample code" after having made changes. If you're going to
  14. //    re-distribute the source, we require that you make it clear
  15. //    in the source that the code was descended from Apple sample
  16. //    code, but that you've made changes.
  17. //    
  18.  
  19. #pragma segment DocSeg
  20.  
  21. #ifndef __DRAG__
  22. #include <Drag.h>
  23. #endif
  24.  
  25. #ifndef __TOOLUTILS__
  26. #include <ToolUtils.h>
  27. #endif
  28.  
  29. #ifndef __STDIO__
  30. #include <Stdio.h>
  31. #endif
  32.  
  33. #ifndef Common_Defs
  34. #include "Common.h"
  35. #endif
  36.  
  37. #ifndef __NAVIGATION__
  38. #include "Navigation.h"
  39. #endif
  40.  
  41. const             printID = -8192;    // string rsrc ID if print driver name
  42. const OSType    strType = 'STR ';    // string resource type
  43.  
  44. extern short         gDocumentCount;
  45. extern Document*    gDocumentList[kMaxDocumentCount];
  46. extern short         gQuitting;
  47. extern short        gCanUndoDrag;
  48. extern WindowPtr    gUndoFrontmost, gLastFrontmost;
  49. extern Boolean        gCanDrag;
  50. extern Boolean        gNavServicesExists;
  51.  
  52. extern pascal OSErr MyTrackingHandler(short message, WindowPtr theWindow, void* handlerRefCon, DragReference theDrag);
  53. extern pascal OSErr MyReceiveDropHandler(WindowPtr theWindow, unsigned long handlerRefCon, DragReference theDrag);
  54.  
  55. void PositionDocumentParts(Document* theDocument);
  56. void DoDrawGrowIcon(WindowPtr theWindow);
  57.  
  58. DragReceiveHandlerUPP     receiveHandler;
  59. DragTrackingHandlerUPP     trackingHandler;
  60. DragSendDataUPP         sendHandler;
  61.  
  62. pascal void myventProc(const     NavEventCallbackMessage callBackSelctor, 
  63.                                                 NavCBRecPtr callBackParms, 
  64.                                                 NavCallBackUserData callBackUD);
  65. NavAskSaveChangesResult OpenAskSaveChanges(unsigned char* docName, Boolean quitting);
  66.  
  67.  
  68. // **********************************************************************
  69. // *
  70. // *    AddText()
  71. // *
  72. // **********************************************************************
  73. void AddText(Document* theDocument, Ptr text, long len)
  74. {
  75.     if (theDocument->theTE != NULL)
  76.         {
  77.         TEInsert(text,len,theDocument->theTE);
  78.         theDocument->dirty = true;
  79.         TESelView(theDocument->theTE);
  80.         AdjustScrollBar((Document*)GetWRefCon(theDocument->theWindow));
  81.         }
  82. }
  83.  
  84.  
  85. // **********************************************************************
  86. // *
  87. // *    AdjustDocumentView()
  88. // *
  89. // **********************************************************************
  90. void AdjustDocumentView(Document* theDocument)
  91. {    
  92.     short    delta, docTop, docTopLimit;
  93.  
  94.     delta = (theDocument->vScrollPos - GetControlValue(theDocument->vScroll)) * ScrollResolution;
  95.  
  96.     if (delta && theDocument->theTE)
  97.         {
  98.         if (delta > 0)
  99.             {
  100.             docTop = (**(theDocument->theTE)).destRect.top;
  101.             docTopLimit = (**(theDocument->theTE)).viewRect.top + TopMargin;
  102.             if (docTop + delta > docTopLimit)
  103.                 delta = docTopLimit - docTop;
  104.             }
  105.         TEScroll(0,delta,theDocument->theTE);
  106.         theDocument->vScrollPos = GetControlValue(theDocument->vScroll);
  107.         }
  108. }
  109.  
  110.  
  111. // **********************************************************************
  112. // *
  113. // *    AdjustScrollBar()
  114. // *
  115. // **********************************************************************
  116. void AdjustScrollBar(Document* theDocument)
  117. {    
  118.     short        docTop, docBottom, viewTop, viewBottom;
  119.     short        offTop, offBottom;
  120.     RgnHandle    viewRgn;
  121.  
  122.     if (theDocument->theTE != NULL)
  123.         {
  124.         docTop = (**(theDocument->theTE)).destRect.top;
  125.         docBottom = docTop + TEGetHeight(32767,0,theDocument->theTE);
  126.         viewTop = (**(theDocument->theTE)).viewRect.top;
  127.         viewBottom = (**(theDocument->theTE)).viewRect.bottom;
  128.     
  129.         offTop = ((viewTop - (docTop - TopMargin)) + ScrollResolution - 1) / ScrollResolution;
  130.         offBottom = (((docBottom + BottomMargin) - viewBottom) + ScrollResolution - 1) / ScrollResolution;
  131.         if (offTop < 0)
  132.             offTop = 0;
  133.         if (offBottom < 0)
  134.             offBottom = 0;
  135.     
  136.         theDocument->vScrollPos = offTop;
  137.     
  138.         SetControlMaximum(theDocument->vScroll,offTop + offBottom);
  139.         SetControlValue(theDocument->vScroll,offTop);
  140.     
  141.         viewRgn = NewRgn();
  142.         RectRgn(viewRgn,&(**(theDocument->theTE)).viewRect);
  143.         SectRgn(viewRgn,theDocument->hiliteRgn,theDocument->hiliteRgn);
  144.         DisposeRgn(viewRgn);
  145.         }
  146. }
  147.  
  148.  
  149. // **********************************************************************
  150. // *
  151. // *    PositionDocumentParts()
  152. // *
  153. // **********************************************************************
  154. void PositionDocumentParts(Document* theDocument)
  155. {    
  156.     Rect globalBounds = theDocument->theWindow->portRect;
  157.     Rect theRect;
  158.  
  159.     // size the vertical scrollbar:
  160.     SizeControl(theDocument->vScroll,kScrollBarWidth,(globalBounds.bottom - globalBounds.top - kScrollBarPos)+4);
  161.     MoveControl(theDocument->vScroll,globalBounds.right+2 - kScrollBarPos,-1);
  162.  
  163.     // size the horizontal scrollbar:
  164.     SizeControl(theDocument->hScroll,(globalBounds.right - globalBounds.left - kScrollBarPos)+4,kScrollBarWidth);
  165.     MoveControl(theDocument->hScroll,-1,(globalBounds.bottom - globalBounds.top - kScrollBarPos)+2);
  166.  
  167.     theRect = globalBounds;
  168.     theRect.right  -= 15;
  169.     theRect.bottom -= 15;
  170.     (**(theDocument->theTE)).viewRect = theRect;
  171.     (**(theDocument->theTE)).destRect.right = theRect.right - RightMargin;
  172.     TECalText(theDocument->theTE);
  173. }
  174.  
  175.  
  176. void SizeDocWindow(Document* theDocument)
  177. {
  178.     short length = 0;
  179.     short width = 0;
  180.     if (theDocument->fPict != NULL)
  181.         {
  182.         if ((**((PicHandle)theDocument->fPict)).picFrame.right >= qd.screenBits.bounds.right)
  183.             width = qd.screenBits.bounds.right-40;
  184.         else
  185.             width = (**((PicHandle)theDocument->fPict)).picFrame.right;
  186.  
  187.         if ((**((PicHandle)theDocument->fPict)).picFrame.bottom >= qd.screenBits.bounds.bottom)
  188.             length = qd.screenBits.bounds.bottom-10-LMGetMBarHeight()-27;
  189.         else
  190.             length = (**((PicHandle)theDocument->fPict)).picFrame.bottom;
  191.         }
  192.     else
  193.         {
  194.         length = qd.screenBits.bounds.bottom-10-LMGetMBarHeight()-27;    
  195.         width = kWindowWidth;
  196.         }
  197.     SizeWindow(theDocument->theWindow,width,length,true);
  198. }
  199.  
  200.  
  201. // **********************************************************************
  202. // *
  203. // *    NewDocument()
  204. // *
  205. // **********************************************************************
  206. Document* NewDocument(Boolean newDocAsPICT)
  207. {    
  208.     OSErr            theErr = noErr;
  209.     Document*        theDocument;
  210.     WindowPtr        theWindow;
  211.     Rect            theRect = {0,0,16,16};
  212.     TextStyle        theStyle;
  213.     TEStyleHandle    theStyleHandle;
  214.     Point            thePoint;
  215.     Rect            theSize;
  216.     short            length = 0, width = 0;
  217.     Str255            windTitle;
  218.     short            offset;
  219.     Rect            bounds;
  220.  
  221.     if (gDocumentCount == kMaxDocumentCount)
  222.         return ((Document*)0L);
  223.         
  224.     theDocument = gDocumentList[gDocumentCount++] = (Document*)NewPtr(sizeof(Document));
  225.     
  226.     // create the window
  227.     offset = gDocumentCount-1;
  228.     theDocument->theWindow = theWindow = NewCWindow(0L,&theSize,(unsigned char*)"\p",false,zoomDocProc,(WindowPtr)-1L,true,0L);
  229.     MoveWindow(theDocument->theWindow,(10+(offset*20)),(27+(offset*20)+LMGetMBarHeight()),true);
  230.     
  231.     bounds = theWindow->portRect;
  232.  
  233.     // setup the window title
  234.     sprintf((char*)windTitle,"untitled %d",gDocumentCount);
  235.     MyC2PStr((char*)windTitle);
  236.     SetWTitle(theDocument->theWindow,windTitle);
  237.     
  238.     SetWRefCon(theWindow,(long)theDocument);
  239.  
  240.     SetPort(theWindow);
  241.     thePoint.v = bounds.top;
  242.     thePoint.h = bounds.left;
  243.  
  244.     LocalToGlobal(&thePoint);
  245.     if (thePoint.h < 10)
  246.         MoveWindow(theWindow,InitialH,InitialV,false);
  247.  
  248.     if (newDocAsPICT)
  249.         {
  250.         theDocument->theTE = NULL;
  251.         theDocument->fPict = NULL;
  252.         theDocument->fPictLength = 0;
  253.         theDocument->fHeader = NULL;
  254.         }
  255.     else
  256.         {
  257.         theDocument->fPict = NULL;
  258.  
  259.         SizeDocWindow(theDocument);
  260.  
  261.         theDocument->vScroll = NewControl(theWindow,&theRect,(ConstStr255Param)"\p",true,0,0,0,scrollBarProc,(long)theDocument);
  262.         theDocument->hScroll = NewControl(theWindow,&theRect,(ConstStr255Param)"\p",true,0,0,0,scrollBarProc,(long)theDocument);
  263.  
  264.         theDocument->theTE = TEStyleNew(&theRect,&theRect);
  265.         (**(theDocument->theTE)).destRect.top    = TopMargin;
  266.         (**(theDocument->theTE)).destRect.left   = LeftMargin;
  267.         (**(theDocument->theTE)).destRect.bottom = 32767;
  268.         
  269.         TEAutoView(true,theDocument->theTE);
  270.  
  271.         TEFeatureFlag(teFOutlineHilite,teBitSet,theDocument->theTE);
  272.  
  273.         theDocument->hiliteRgn = NewRgn();
  274.         theStyleHandle = TEGetStyleHandle(theDocument->theTE);
  275.         (**theStyleHandle).teRefCon = (long)theDocument;
  276.  
  277.         theStyle.tsFont = 21;
  278.         theStyle.tsSize = 12;
  279.         TESetStyle(doFont + doSize,&theStyle,false,theDocument->theTE);
  280.         
  281.         theDocument->vScrollPos = 0;
  282.         theDocument->undoDragText = 0L;
  283.         
  284.         PositionDocumentParts(theDocument);
  285.  
  286.         if (gCanDrag && theDocument->theTE != NULL)
  287.             {
  288.             receiveHandler = NewDragReceiveHandlerProc(&MyReceiveDropHandler);
  289.             trackingHandler = NewDragTrackingHandlerProc(&MyTrackingHandler);
  290.             
  291.             theErr = InstallReceiveHandler(receiveHandler,theWindow,(void*)theDocument);
  292.             theErr = InstallTrackingHandler(trackingHandler,theWindow,(void*)theDocument);
  293.             }
  294.         }
  295.     
  296.     theDocument->fRefNum = 0;
  297.     theDocument->dirty = false;
  298.     
  299.     return theDocument;
  300. }
  301.  
  302.  
  303. // **********************************************************************
  304. // *
  305. // *    OpenAskSaveChanges()
  306. // *
  307. // **********************************************************************
  308. NavAskSaveChangesResult OpenAskSaveChanges(unsigned char* docName, Boolean quitting)
  309. {
  310.     OSStatus                theStatusErr     = noErr;
  311.     OSErr                     theErr             = noErr;
  312.     NavAskSaveChangesResult    reply             = 0;
  313.     NavAskSaveChangesAction    action             = 0;
  314.     NavEventUPP                eventUPP = NewNavEventProc(myEventProc);
  315.     NavDialogOptions        dialogOptions;
  316.     
  317.     if (quitting)
  318.         action = kNavSaveChangesQuittingApplication;
  319.     else
  320.         action = kNavSaveChangesClosingDocument;
  321.         
  322.     BlockMoveData(docName,dialogOptions.savedFileName,docName[0]+1);
  323.     GetIndString(dialogOptions.clientName,rAppStringsID,sApplicationName);
  324.  
  325.     theErr = NavAskSaveChanges(    &dialogOptions,
  326.                                 action,
  327.                                 &reply,
  328.                                 eventUPP,
  329.                                 (NavCallBackUserData)&gDocumentList);
  330.     
  331.     DisposeRoutineDescriptor(eventUPP);
  332.  
  333.     return reply;
  334. }
  335.  
  336.  
  337. // **********************************************************************
  338. // *
  339. // *    CloseDocument()
  340. // *
  341. // **********************************************************************
  342. void CloseDocument(Document* theDocument, Boolean quitting)
  343. {    
  344.     OSErr    theErr = noErr;
  345.     short    index;
  346.     Str255    theName;
  347.  
  348.     index = 0;
  349.     while ((gDocumentList[index] != theDocument) && (index < kMaxDocumentCount))
  350.         index++;
  351.  
  352.     if (gDocumentList[index] == theDocument)
  353.         {
  354.         if (theDocument->dirty)
  355.             {
  356.             if (gNavServicesExists)
  357.                 {
  358.                 NavAskSaveChangesResult result = 0;
  359.             GetWTitle(theDocument->theWindow,(unsigned char*)&theName);
  360.             result = OpenAskSaveChanges(theName,quitting);
  361.             switch (result)
  362.                 {
  363.                 case kNavAskSaveChangesSave:
  364.                     if (!DoSaveDocument(theDocument))
  365.                         {
  366.                         gQuitting = false;    // don't quit yet!
  367.                         //return;
  368.                         }
  369.                     break;
  370.                 case kNavAskSaveChangesCancel:
  371.                     gQuitting = false;    // don't quit yet!
  372.                     //return;
  373.                     break;
  374.                 }
  375.             if (result == kNavAskSaveChangesCancel)
  376.                 return;    // don't close the document
  377.             }
  378.             else
  379.                 {
  380.                 short response = 0;
  381.                 Str255 theVerb;
  382.                 GetWTitle(theDocument->theWindow,(unsigned char*)&theName);
  383.                 GetIndString((unsigned char*)&theVerb,rAppStringsID,(gQuitting) ? slQuittingIndex : slClosingIndex);
  384.                 ParamText((ConstStr255Param)&theName,(ConstStr255Param)&theVerb,(ConstStr255Param)"\p",(ConstStr255Param)"\p");
  385.                 SetCursor(&qd.arrow);
  386.                 response = Alert(rSaveChangesID,0L);
  387.  
  388.                 if (response == 1)
  389.                     {            // Save
  390.                     if (!DoSaveDocument(theDocument))
  391.                         {
  392.                         gQuitting = false;
  393.                         return;
  394.                         }
  395.                     }
  396.                 else
  397.                     if (response == 3)
  398.                         {    // Don't Save
  399.                         ;
  400.                         }
  401.                     else
  402.                         {    // Cancel
  403.                         gQuitting = false;
  404.                         return;
  405.                         }
  406.                 }
  407.             }
  408.  
  409.         if (theDocument->fRefNum)
  410.             FSClose(theDocument->fRefNum);
  411.  
  412.         if (gCanDrag && theDocument->theTE != NULL)
  413.             {
  414.             theErr = RemoveReceiveHandler(receiveHandler,theDocument->theWindow);
  415.             theErr = RemoveTrackingHandler(trackingHandler,theDocument->theWindow);
  416.             }
  417.         
  418.         if (theDocument->theTE != NULL)
  419.             {
  420.             DisposeRgn(theDocument->hiliteRgn);
  421.             TEDispose(theDocument->theTE);
  422.             
  423.             if (theDocument->undoDragText)
  424.                 {
  425.                 DisposeHandle(theDocument->undoDragText);
  426.                 theDocument->undoDragText = 0L;
  427.                 }
  428.             }
  429.         else
  430.             {
  431.             if (theDocument->fPict != NULL)
  432.                 KillPicture((PicHandle)theDocument->fPict);    
  433.             if (theDocument->fHeader != NULL)
  434.                 DisposeHandle(theDocument->fHeader);
  435.             }
  436.  
  437.         DisposeWindow(theDocument->theWindow);
  438.  
  439.         while (index < kMaxDocumentCount)
  440.             {
  441.             gDocumentList[index] = gDocumentList[index + 1];
  442.             index++;
  443.             }
  444.  
  445.         DisposePtr((Ptr)theDocument);
  446.         gDocumentCount--;
  447.     }
  448. }
  449.  
  450.  
  451. // **********************************************************************
  452. // *
  453. // *    DoActivateDocument()
  454. // *
  455. // **********************************************************************
  456. void DoActivateDocument(Document* theDocument, short activate)
  457. {    
  458.     if (theDocument->theTE != NULL)
  459.         {
  460.         if (activate)
  461.             {
  462.             TEActivate(theDocument->theTE);
  463.             HiliteControl(theDocument->vScroll,0);
  464.             HiliteControl(theDocument->hScroll,0);
  465.             DoDrawGrowIcon(theDocument->theWindow);
  466.             TEGetHiliteRgn(theDocument->hiliteRgn,theDocument->theTE);
  467.             }
  468.         else
  469.             {
  470.             TEDeactivate(theDocument->theTE);
  471.             HiliteControl(theDocument->vScroll,255);
  472.             HiliteControl(theDocument->hScroll,255);
  473.             DoDrawGrowIcon(theDocument->theWindow);
  474.             }
  475.         }
  476. }
  477.  
  478.  
  479. // **********************************************************************
  480. // *
  481. // *    IsDocumentWindow()
  482. // *
  483. // **********************************************************************
  484. Document* IsDocumentWindow(WindowPtr theWindow)
  485. {    
  486.     short        index = 0;
  487.     Document*    theDocument;
  488.  
  489.     theDocument = (Document*)GetWRefCon(theWindow);
  490.  
  491.     while ((gDocumentList[index] != theDocument) && (index < gDocumentCount))
  492.         index++;
  493.  
  494.     if (gDocumentList[index] == theDocument)
  495.         return(theDocument);
  496.     else
  497.         return((Document*)0L);
  498. }
  499.  
  500.  
  501. // **********************************************************************
  502. // *
  503. // *    DoSelectAllDocument()
  504. // *
  505. // **********************************************************************
  506. void DoSelectAllDocument(Document* theDocument)
  507. {
  508.     if (theDocument && (theDocument->theTE))
  509.         TESetSelect(0,32767,theDocument->theTE);
  510. }
  511.  
  512.  
  513. // **********************************************************************
  514. // *
  515. // *    DisableUndoDrag()
  516. // *
  517. // **********************************************************************
  518. void DisableUndoDrag()
  519. {    
  520.     short        index;
  521.     Document*    theDoc;
  522.  
  523.     gCanUndoDrag = slCantUndo;
  524.  
  525.     index = gDocumentCount;
  526.     while (index--)
  527.         {
  528.         theDoc = gDocumentList[index];
  529.         if (theDoc->undoDragText)
  530.             {
  531.             DisposeHandle(theDoc->undoDragText);
  532.             theDoc->undoDragText = 0L;
  533.             }
  534.         }
  535. }
  536.  
  537.  
  538. // **********************************************************************
  539. // *
  540. // *    DoUndoDrag()
  541. // *
  542. // **********************************************************************
  543. void DoUndoDrag()
  544. {    
  545.     short        index, selStart, selEnd;
  546.     Document*    theDoc;
  547.     Handle        theText;
  548.     WindowPtr    theWindow;
  549.     Rect        theRect;
  550.  
  551.     if (gCanUndoDrag != slCantUndo)
  552.         {
  553.         theWindow = 0L;
  554.         index = gDocumentCount;
  555.         while (index--)
  556.             {
  557.             theDoc = gDocumentList[index];
  558.  
  559.             SetPort(theDoc->theWindow);
  560.             
  561.             if (theText = theDoc->undoDragText)
  562.                 {
  563.                 Rect        bounds = theDoc->theWindow->portRect;
  564.  
  565.                 theDoc->undoDragText = (**theDoc->theTE).hText;
  566.                 (**theDoc->theTE).hText = theText;
  567.  
  568.                 TECalText(theDoc->theTE);
  569.  
  570.                 selStart = theDoc->undoSelStart;
  571.                 selEnd   = theDoc->undoSelEnd;
  572.                 TESetSelect(selStart,selEnd,theDoc->theTE);
  573.                 theDoc->undoSelStart = theDoc->lastSelStart;
  574.                 theDoc->undoSelEnd   = theDoc->lastSelEnd;
  575.                 theDoc->lastSelStart = selStart;
  576.                 theDoc->lastSelEnd   = selEnd;
  577.  
  578.                 theRect = bounds;
  579.                 theRect.right  -= 15;
  580.                 theRect.bottom -= 15;
  581.                 EraseRect(&theRect);
  582.                 TEUpdate(&theRect,theDoc->theTE);
  583.                 }
  584.             }
  585.  
  586.         if (gCanUndoDrag == slUndoDrag)
  587.             gCanUndoDrag = slRedoDrag;
  588.         else
  589.             gCanUndoDrag = slUndoDrag;
  590.  
  591.         theWindow = gUndoFrontmost;
  592.         gUndoFrontmost = gLastFrontmost;
  593.         gLastFrontmost = theWindow;
  594.         }
  595. }
  596.  
  597.  
  598. // *****************************************************************************
  599. // *
  600. // *    DoDrawGrowIcon()
  601. // *
  602. // *****************************************************************************
  603. void DoDrawGrowIcon(WindowPtr theWindow)
  604. {
  605.     RgnHandle saveClipRgn = NewRgn();
  606.     Rect tempRect;
  607.  
  608.     if (saveClipRgn)
  609.         {
  610.         GetClip(saveClipRgn);
  611.     
  612.         SetRect(&tempRect,
  613.                 theWindow->portRect.right-15,
  614.                 theWindow->portRect.bottom-15,
  615.                 theWindow->portRect.right,
  616.                 theWindow->portRect.bottom);
  617.         ClipRect(&tempRect);
  618.         DrawGrowIcon(theWindow);
  619.         
  620.         SetClip(saveClipRgn);
  621.         DisposeRgn(saveClipRgn);
  622.         }
  623.     else
  624.         DrawGrowIcon(theWindow);
  625. }
  626.  
  627.  
  628. // *****************************************************************************
  629. // *
  630. // *    UpdateWindow()
  631. // *
  632. // *    Update event is received for a document window.
  633. // *
  634. // *****************************************************************************
  635. void UpdateWindow(Document* theDocument)
  636. {    
  637.     WindowPtr     theWindow = theDocument->theWindow;
  638.     Rect        bounds = theDocument->theWindow->portRect;
  639.     
  640.     SetPort(theWindow);
  641.     
  642.     BeginUpdate(theWindow);
  643.  
  644.     EraseRect(&bounds);
  645.     if (theDocument->theTE != NULL)
  646.         {
  647.         DrawControls(theWindow);
  648.         DoDrawGrowIcon(theWindow);
  649.         if (theDocument->theTE)
  650.             TEUpdate(&bounds,theDocument->theTE);
  651.         }
  652.     else
  653.         {
  654.         if (theDocument->fPict != NULL)
  655.             DrawPicture((PicHandle)theDocument->fPict,&((**((PicHandle)theDocument->fPict)).picFrame));
  656.         }
  657.     EndUpdate(theWindow);
  658. }
  659.  
  660.  
  661. // *****************************************************************************
  662. // *
  663. // *    DoZoomDocument()
  664. // *
  665. // *****************************************************************************
  666. void DoZoomDocument(Document* theDocument, WindowPtr theWindow, short thePart)
  667. {
  668.     GrafPtr    oldPort;
  669.     GetPort(&oldPort);
  670.     
  671.     SetPort(theWindow);
  672.     EraseRect(&theWindow->portRect);
  673.     ZoomWindow(theWindow,thePart,theWindow == FrontWindow());
  674.     
  675.     if (theDocument->theTE != NULL)
  676.         {
  677.         PositionDocumentParts((Document*)GetWRefCon(theWindow));
  678.         AdjustScrollBar((Document*)GetWRefCon(theWindow));
  679.         DoDrawGrowIcon(theWindow);
  680.         }
  681.  
  682.     InvalRect(&theWindow->portRect);
  683.  
  684.     SetPort(oldPort);
  685. }
  686.  
  687.  
  688. // *****************************************************************************
  689. // *
  690. // *    GrowDocumentWindow()
  691. // *
  692. // *****************************************************************************
  693. void GrowDocumentWindow(WindowPtr theWindow, Point thePoint)
  694. {    
  695.     long    result;
  696.     Rect    sizeRect;
  697.     Rect    bounds = theWindow->portRect;
  698.  
  699.     SetPort(theWindow);
  700.     
  701.     sizeRect = qd.screenBits.bounds;
  702.     if (!(result = GrowWindow(theWindow,thePoint,&sizeRect)))
  703.         return;
  704.         
  705.     SizeWindow(theWindow,LoWord(result),HiWord(result),false);
  706.  
  707.     PositionDocumentParts((Document*)GetWRefCon(theWindow));
  708.  
  709.     AdjustScrollBar((Document*)GetWRefCon(theWindow));
  710.  
  711.     DoDrawGrowIcon(theWindow);
  712.  
  713.     bounds = theWindow->portRect;
  714.     InvalRect(&bounds);
  715. }